package com.kingdee.eas.hr.quali.handler;

import java.sql.SQLException;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.eas.base.permission.UserInfo;
import com.kingdee.eas.util.app.ContextUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.json.GridDataEntity;
import com.kingdee.shr.base.syssetting.web.handler.ListHandler;
import com.kingdee.shr.compensation.util.SqlUtil;

public class MyAssignOfCommentListHandler extends ListHandler {

	@Override
	protected void afterGetListData(HttpServletRequest request, HttpServletResponse response,GridDataEntity gridDataEntity) throws SHRWebException {
		super.afterGetListData(request, response, gridDataEntity);
		Context ctx = SHRContext.getInstance().getContext();
		List rows = gridDataEntity.getRows();
		for(int i = 0,size = rows.size(); i < size; i++){
			Map rowData = (Map)rows.get(i);
			String assignId = String.valueOf(rowData.get("id"));
			String sql = "select FID from  T_BAS_AssignRead where FASSIGNID = '"+assignId+"'";
			try {
				IRowSet iRowSet = SqlUtil.executeQuery(ctx, sql);
				if(iRowSet.next()){
					rowData.put("sourceAssignID", iRowSet.getString("FID"));
				}
			} catch (BOSException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	@Override
	protected FilterInfo getDefaultFilter(HttpServletRequest request, HttpServletResponse response)throws SHRWebException {
		Context ctx = SHRContext.getInstance().getContext();
		UserInfo user = ContextUtil.getCurrentUserInfo(ctx);
		String uipk = request.getParameter("uipk");
		FilterInfo filterInfo = new FilterInfo();
		filterInfo.getFilterItems().add(new FilterItemInfo("personUserID", user.getId(), CompareType.EQUALS));
		if(uipk.equals("appraisalTask")){
			filterInfo.getFilterItems().add(new FilterItemInfo("billEntity", "com.kingdee.eas.hr.quali.app.QualiCommentPlan", CompareType.EQUALS));
		}else{
			Set<String> set = new HashSet<String>();
			set.add("com.kingdee.eas.hr.quali.app.QualiCommentPlan");
			set.add("com.kingdee.eas.hr.quali.app.QualificationApplyBill");
			set.add("com.kingdee.eas.hr.quali.app.SummaryApproval");
			filterInfo.getFilterItems().add(new FilterItemInfo("billEntity", set, CompareType.INCLUDE));
		}
		return filterInfo;
		
	}
	
	
}
